package org.example.basics;


public class Demo1 {
    public static void main(String[] args) {
//        test1();
//        test2();
//        test3();
//        test4();
//        test5();
//        test6();
//        test7();
//        test8();
    }

    private static void test8() {
        int a = 5;
        a &= 3;
        System.out.println(a);  // 1
    }

    private static void test7() {
        System.out.println(5 & 3);  // 1，5(0101) & 3(0011) = 1(0001)
        System.out.println(~5);     // -6
        System.out.println(5 | 3);  // 7
        System.out.println(5 ^ 3);  // 6

        System.out.println(5<<2);   // 20
        System.out.println(-5<<2);  // -20

        System.out.println(5>>2);   // 1
        System.out.println(-5>>2);  // -2

        System.out.println(5>>>3);  // 0
        System.out.println(-5>>>3); // 536870911
        System.out.println(get32BitBinString(-5>>>3));  // 00011111111111111111111111111111
    }

    private static String get32BitBinString(int number) {
        StringBuilder sBuilder = new StringBuilder();
        for (int i = 0; i < 32; i++){
            sBuilder.append(number & 1);
            number = number >>> 1;
        }
        return sBuilder.reverse().toString();
    }

    private static void test6() {
        System.out.println(!(!false & true));
    }

    private static void test5() {
        int a = 10;
        System.out.println("123" + ++a);    // 12311
        System.out.println(a);  // 11
        System.out.println("123" + a++);    // 12311
        System.out.println(a);  // 12
    }

    private static void test4() {
        System.out.println(1 + "abc" + 1);
        System.out.println(1 + 2 + "abc" + 2 + 1);
        String name = "黑默丁格";
        System.out.println("我的名字是" + name);
        System.out.println("asd" + 's');
    }

    private static void test3() {
        int a = 10;
        double d = a;           // 自动类型转换
        short s = (short) a;    // 强制类型转换
        System.out.println(s);  // 10
        System.out.println(d);  // 10.0

        byte b = 1;
        s = b;
        System.out.println(s);

        double dd = 12.3;
        int bc = (int) dd;
        System.out.println(bc); // 12
    }

    private static void test2() {
        //1.定义byte类型的变量
        byte a = 10;
        System.out.println(a);

        //2.定义short类型的变量
        short b = 20;
        System.out.println(b);

        //3.定义int类型的变量
        int c = 30;
        System.out.println(c);

        //4.定义long类型的变量，那么在数据值的后面需要加上L后缀。（大小写都可以，建议大写。）
        long d = 123456789123456789L;
        System.out.println(d);

        //5.定义float类型的变量，那么在数据值的后面需要加上F后缀。（大小写都可以）
        float e = 10.1F;
        System.out.println(e);

        //6.定义double类型的变量
        double f = 20.3;
        System.out.println(f);

        //7.定义char类型的变量
        char g = 'a';
        System.out.println(g);

        //8.定义boolean类型的变量
        boolean h = true;
        System.out.println(h);
    }

    private static void test1() {
        //1.变量名不允许重复
        int x = 10;
//        int x = 20;
        System.out.println(x);  // 10

        //2.一条语句可以定义多个变量,了解。
        int a = 10, b = 20, c = 20, d = 20;
        System.out.println(a);  // 10
        System.out.println(b);  // 20


        //3.变量在使用之前必须要赋值
        int y = 30;
        System.out.println(y);  // 30
    }
}
